── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr 1.1.4 ✔ readr 2.1.5
✔ forcats 1.0.0 ✔ stringr 1.5.1
✔ ggplot2 3.5.1 ✔ tibble 3.2.1
✔ lubridate 1.9.3 ✔ tidyr 1.3.1
✔ purrr 1.0.2
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag() masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(leaflet)library(sf)
Linking to GEOS 3.11.0, GDAL 3.5.3, PROJ 9.1.0; sf_use_s2() is TRUE
fl_education_data <-get_acs(geography ="tract", # Use "block group" for block group levelvariables ="B15003_022", # Example: Bachelor's degree or higherstate ="FL", # Floridayear =2021, # Specify the yearsurvey ="acs5", # 5-year ACS datageometry =TRUE# Set to TRUE if you want spatial data)
Getting data from the 2017-2021 5-year ACS
fl_education_data <- fl_education_data %>%rename(Tract = NAME,Education_Variable = variable,Estimate = estimate,Margin_of_Error = moe )# Add a new column for popup text (optional but useful for interactivity)fl_education_data <- fl_education_data %>%mutate(Popup_Text =paste("Tract: ", Tract, "<br>","Estimate: ", Estimate, "<br>","Margin of Error: ", Margin_of_Error ) )
# Define a color palette based on the Estimate valuespal <-colorNumeric(palette ="viridis", # You can use "viridis", "plasma", or other color schemesdomain = fl_education_data$Estimate)# Create the interactive mapleaflet_map <-leaflet(fl_education_data) %>%addTiles() %>%# Add base map tilesaddPolygons(color =~pal(Estimate), # Color polygons based on Estimateweight =1, # Border thicknessopacity =1, # Border opacityfillOpacity =0.7, # Fill opacitypopup =~Popup_Text, # Popup text when clicking on a tracthighlightOptions =highlightOptions(weight =2, # Highlight border thicknesscolor ="white", # Highlight border colorfillOpacity =0.9, # Highlight fill opacitybringToFront =TRUE# Bring highlighted tract to front ) ) %>%addLegend(position ="bottomright", # Position of the legendpal = pal, # Color palettevalues =~Estimate, # Values for the legendtitle ="Estimate of Bachelor's Degree or Higher"# Legend title )
Warning: sf layer has inconsistent datum (+proj=longlat +datum=NAD83 +no_defs).
Need '+proj=longlat +datum=WGS84'